package dyyx;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

@Component
public class MyFilter extends ZuulFilter {
	@Override
	public String filterType() {
		return FilterConstants.PRE_TYPE;
	}

	@Override
	public int filterOrder() {
		return 0;
	}

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
		HttpServletRequest request = ctx.getRequest();
		
		String uri = request.getRequestURI();
		String url = request.getRequestURL().toString();
		String servletPath = request.getServletPath();
		
		System.out.println(new Date()+" uri="+uri+",url="+url+",servletPath="+servletPath);
		
		/*
	    Object accessToken = request.getParameter("token");

		if (accessToken == null) {
			ctx.setSendZuulResponse(false);
			ctx.setResponseStatusCode(401);
			try {
				// ctx.getResponse().setHeader("Content-Type", "text/html;charset=UTF-8");
				// ctx.getResponse().getWriter().write("登录信息为空！");
			} catch (Exception e) {
				// 
			}
			return null;
		}
		*/
		return null;
	}
}
